package cn.cvs.service.supplier;


import cn.cvs.dao.SupplierMapper;
import cn.cvs.pojo.Supplier;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SupplierServiceImpl implements SupplierService{

    @Resource
    private SupplierMapper supplierMapper;

    /**
     * 查询供应商列表
     *
     * @return
     * @throws Exception
     */
    @Override
    public List<Supplier> findAllSupplier(Integer pageIndex, Integer pageSize, String querySupCode, String querySupName) throws Exception {
        List<Supplier> list = supplierMapper.queryAllSupplier((pageIndex-1)*pageSize,pageSize,querySupCode,querySupName);
        return list;
    }

    @Override
    public Integer totalCount(String querySupCode, String querySupName) throws Exception {
        return supplierMapper.findAllcount(querySupCode, querySupName);
    }
    /**
     * 添加供应商
     *
     * @param supplier
     * @return
     * @throws Exception
     */
    @Override
    public boolean addSupplier(Supplier supplier) throws Exception {
        Integer row = supplierMapper.addSupplier(supplier);
        if (row>0){
            return true;
        }else {
            return false;
        }

    }

    /**
     * 通过id获取供应商对象
     *
     * @param id
     * @return
     * @throws Exception
     */
    @Override
    public Supplier findSupplierById(String id) throws Exception {
        return supplierMapper.querySupplierById(id);
    }

    /**
     * 修改供应商信息
     *
     * @param supplier
     * @return
     * @throws Exception
     */
    @Override
    public boolean updateSupplier(Supplier supplier) throws Exception {
        if (supplierMapper.modifySupplier(supplier)){
            return true;
        }
        return false;
    }

    /**
     * 获取所有供应商信息
     *
     * @return
     * @throws Exception
     */
    @Override
    public List<Supplier> findAllSupplier() throws Exception {
        return supplierMapper.querySupplierList();
    }

    /**
     * 删除供应商
     *
     * @param id
     * @return
     * @throws Exception
     */
    @Override
    public boolean deleteSupplier(String id) throws Exception {

        if (supplierMapper.delSupplierById(id)>0){
            return true;
        }
        return false;
    }
}
